package com.nhc.view;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Resources;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.astrob.nhcmap.R;
import com.astrob.util.SysUtils;
import com.nhc.model.TripDatainfo;
import com.nhc.model.TripItem;

import zuo.biao.library.base.BaseModel;
import zuo.biao.library.base.BaseView;
import zuo.biao.library.util.StringUtil;

public class TripItemView extends BaseView<TripItem> implements OnClickListener {
    private static final String TAG = "TripItemView";

    public TripItemView(Activity context, Resources resources) {
        super(context, resources);
    }

    public TextView tvTripItemTitle;
    public TextView tvTripItemContentmid;
    public TextView tvTripItemContent;
    public TextView tvTripItemUnit;

    @SuppressLint("InflateParams")
    @Override
    public View createView(LayoutInflater inflater) {
        convertView = inflater.inflate(R.layout.tripitem_view, null);

        tvTripItemTitle = findViewById(R.id.tvTripItemTitle);
        tvTripItemContent = findViewById(R.id.tvTripItemContent);
//        tvTripItemContentmid = findViewById(R.id.tvTripItemContentmid, this);
        tvTripItemContentmid = findViewById(R.id.tvTripItemContentmid);
        tvTripItemUnit = findViewById(R.id.tvTripItemUnit);
        return convertView;
    }

    @Override
    public void bindView(TripItem data) {
        if (data == null) {
            data = new TripItem();
        }

        if (data.getContent().length() < 1) {
            data.setContent(TripDatainfo.DEDAUTSTR);
        }
        this.data = data;

        tvTripItemContent.setVisibility(View.VISIBLE);
        tvTripItemUnit.setVisibility(View.VISIBLE);
        tvTripItemContentmid.setVisibility(View.VISIBLE);

        tvTripItemTitle.setText(StringUtil.getTrimedString(data.getTitle()));
        tvTripItemContent.setText(StringUtil.getTrimedString(data.getContent()));
        tvTripItemContentmid.setText(StringUtil.getTrimedString(data.getContent()));
        tvTripItemUnit.setText(StringUtil.getTrimedString(data.getUnit()));

        if (SysUtils.getInstance().is240x320) {
            if (data.getUnit().length() > 0) {
                tvTripItemContentmid.setVisibility(View.GONE);

                if (data.getContent().length() > 6) {
                    tvTripItemContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                } else {
                    tvTripItemContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
                }

            } else {
                tvTripItemContent.setVisibility(View.GONE);
                tvTripItemUnit.setVisibility(View.GONE);

                if (data.getContent().length() > 12) {
                    tvTripItemContentmid.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                } else {
                    tvTripItemContentmid.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
                }
            }
        } else {
            if (data.getUnit().length() > 0) {
                tvTripItemContentmid.setVisibility(View.GONE);

                if (data.getContent().length() > 6) {
                    tvTripItemContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                } else {
                    tvTripItemContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 28);
                }

            } else {
                tvTripItemContent.setVisibility(View.GONE);
                tvTripItemUnit.setVisibility(View.GONE);

                if (data.getContent().length() > 12) {
                    tvTripItemContentmid.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
                } else {
                    tvTripItemContentmid.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 28);
                }
            }
        }


    }

    @Override
    public void onClick(View v) {
        if (BaseModel.isCorrect(data) == false) {
            return;
        }
        switch (v.getId()) {
            case R.id.tvTripItemContentmid:
//			bindView(data);
                break;
            default:
                break;
        }
    }
}